// pages/earnings/earnings.js
const app = getApp()
const util = require('../../utils/util.js')
const timety = require('../../utils/timety.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
        bodyp:false, 
        title: "点击查看详情",
        icoimg: "images/la.png",
        eqnun:1,//点击查看状态

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
          this.setData({
                  headerheight: app.globalData.navHeight
          })
          this.request()

  },
        login: function () {
                var that = this
                wx.login({
                        success: function (res) {
                                var code = res.code
                                var data = {
                                        userCode: code,
                                        userImageUrl: "",
                                        userName: ""
                                }
                                util.promotion(app.globalData.appurl + "/qinqiang/user", "POST", data, that.succeed)
                        }
                })
        },
        succeed: function (res) {
                wx.setStorageSync('tekon', res.data.token)
                wx.setStorageSync('userInfo', res.data.user)
                this.request()

        },
        request:function(){
                wx.showNavigationBarLoading()
                wx.showLoading({
                        title: '玩命加载中...',
                })
                var data = {
                        user_id: wx.getStorageSync('userInfo').id,
                        pageIndex: 1,
                        pageSize: 20,
                }
                var header = {
                        'authorization': wx.getStorageSync('tekon'),
                        'content-type': "application/x-www-form-urlencoded"
                }
                util.formhttp(app.globalData.appurl + '/mission/watchTime', 'get', '', header, this.watchTimedata);


        },
        watchTimedata:function(res){
        //   console.log(res)
                if (res.status == 401) {
                        this.login()
                }
          wx.hideNavigationBarLoading()
          wx.hideLoading()
                var list = [];
                for (var inde in res.data.watchCoinsList) {
                        var temp = {
                                coins: res.data.watchCoinsList[inde].coins,
                                tag_name: res.data.watchCoinsList[inde].tag_name,
                                create_time: timety.GMTToStr(new Date().getTime(res.data.watchCoinsList[inde].create_time))
                        }
                        list.push(temp)
                }
                this.setData({
                        watchCoins: res.data.watchCoins,
                        watchCoinsList: list
                })
        },
      
        wallet:function(){
                wx.navigateTo({
                        url: '/pages/wallet/wallet',
                })
        },
        show:function(e){
                console.log(e.currentTarget.dataset.num)
                if (e.currentTarget.dataset.num==1){
                        this.setData({
                                title:"收起详情",
                                eqnun: 0,
                                icoimg:"images/sou.png",
                                bodyp: true
                        })
                }else{
                        this.setData({
                                title: "点击查看详情 ",
                                eqnun: 1,
                                icoimg: "images/la.png",
                                bodyp: false
                        })
                }
        },
  
})